package cn.bugstack.test.domain;

import cn.bugstack.domain.strategy.model.entity.RaffleAwardEntity;
import cn.bugstack.domain.strategy.model.entity.RaffleFactoryEntity;
import cn.bugstack.domain.strategy.service.IRaffleStrategy;
import cn.bugstack.domain.strategy.service.armory.IStrategyArmory;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.ReflectionTestUtils;

import javax.annotation.Resource;

/**
 * @author Lenovo
 * @version 1.0
 * @description: TODO
 * @date 2025/5/17 19:26
 */
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class RaffleStrategyTest {

    @Resource
    private IRaffleStrategy raffleStrategy;

    @Resource
    private IStrategyArmory strategyArmory;

    @Before
    public void setup() {
        // 策略装配 100001、100002、100003
        log.info("测试结果：{}", strategyArmory.assembleLotteryStrategy(100001L));
//        log.info("测试结果：{}", strategyArmory.assembleLotteryStrategy(100002L));
//        log.info("测试结果：{}", strategyArmory.assembleLotteryStrategy(100003L));
        log.info("测试结果：{}", strategyArmory.assembleLotteryStrategy(100006L));

    }

    @Test
    public void testRaffleStrategy() {
        RaffleFactoryEntity raffleFactoryEntity = new RaffleFactoryEntity().builder()
                .userId("psx")
                .strategyId(100006L)
                .build();

        RaffleAwardEntity raffleAwardEntity = raffleStrategy.performRaffle(raffleFactoryEntity);

        log.info("请求参数：{}", JSON.toJSONString(raffleFactoryEntity));
        log.info("测试结果：{}", JSON.toJSONString(raffleAwardEntity));
    }

    @Test
    public void test_performRaffle_blackList() {
        RaffleFactoryEntity raffleFactoryEntity = new RaffleFactoryEntity().builder()
                .userId("user003")
                .strategyId(100001L)
                .build();

        RaffleAwardEntity raffleAwardEntity = raffleStrategy.performRaffle(raffleFactoryEntity);

        log.info("请求参数：{}", JSON.toJSONString(raffleFactoryEntity));
        log.info("测试结果：{}", JSON.toJSONString(raffleAwardEntity));

    }

    @Test
    public void test_raffle_center_rule_lock() {
        RaffleFactoryEntity raffleFactoryEntity = new RaffleFactoryEntity().builder()
                .userId("psx")
                .strategyId(100003L)
                .build();
        RaffleAwardEntity raffleAwardEntity = raffleStrategy.performRaffle(raffleFactoryEntity);

        log.info("请求参数：{}", JSON.toJSONString(raffleFactoryEntity));
        log.info("测试结果：{}", JSON.toJSONString(raffleAwardEntity));
    }

}
